package com.androidx.p013lv.mine.novel.fragment;

import android.os.Bundle;
import android.view.View;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.NovelHistory;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.databinding.FragmentMineBuyNovelBinding;
import com.androidx.p013lv.mine.model.MineNovelHistoryModel;
import com.androidx.p013lv.mine.novel.adpter.NovelHistoryAdapterType;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import java.util.List;

/* renamed from: com.androidx.lv.mine.novel.fragment.MineHistoryNovelFragment */
public class MineHistoryNovelFragment extends LazyFragment<FragmentMineBuyNovelBinding> implements ItemClickListener, OnRefreshLoadMoreListener {
    NovelHistoryAdapterType adapter;
    private MineNovelHistoryModel model;
    int page = 0;

    public static MineHistoryNovelFragment newInstance() {
        Bundle bundle = new Bundle();
        bundle.putString("", "");
        MineHistoryNovelFragment mineHistoryNovelFragment = new MineHistoryNovelFragment();
        mineHistoryNovelFragment.setArguments(bundle);
        return mineHistoryNovelFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return C1207R.C1212layout.fragment_mine_buy_novel;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        this.model = (MineNovelHistoryModel) new ViewModelProvider(this).get(MineNovelHistoryModel.class);
        ((FragmentMineBuyNovelBinding) this.binding).refresh.setOnRefreshListener(this);
        ((FragmentMineBuyNovelBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((FragmentMineBuyNovelBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        this.adapter = new NovelHistoryAdapterType();
        ((FragmentMineBuyNovelBinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.setItemListener(this);
        ((FragmentMineBuyNovelBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.novel.fragment.MineHistoryNovelFragment.View$OnClickListenerC13801 */

            public void onClick(View view) {
                MineHistoryNovelFragment.this.page = 0;
                MineHistoryNovelFragment.this.model.getHistoryVideo(MineHistoryNovelFragment.this.page);
            }
        });
        this.model.data().observe(this, new Observer<List<NovelHistory>>() {
            /* class com.androidx.p013lv.mine.novel.fragment.MineHistoryNovelFragment.C13812 */

            public void onChanged(List<NovelHistory> list) {
                ((FragmentMineBuyNovelBinding) MineHistoryNovelFragment.this.binding).statusLayout.hideLoading();
                ((FragmentMineBuyNovelBinding) MineHistoryNovelFragment.this.binding).refresh.finishRefresh();
                ((FragmentMineBuyNovelBinding) MineHistoryNovelFragment.this.binding).refresh.finishLoadMore();
                if (MineHistoryNovelFragment.this.page == 0) {
                    if (list == null || list.size() == 0) {
                        ((FragmentMineBuyNovelBinding) MineHistoryNovelFragment.this.binding).statusLayout.showEmpty();
                        return;
                    }
                    MineHistoryNovelFragment.this.adapter.setDomain(SpUtils.getInstance().getString("domain"));
                    MineHistoryNovelFragment.this.adapter.setData(list);
                } else if (list == null || list.size() == 0) {
                    ((FragmentMineBuyNovelBinding) MineHistoryNovelFragment.this.binding).refresh.finishLoadMoreWithNoMoreData();
                } else {
                    MineHistoryNovelFragment.this.adapter.setDatasInEnd(list);
                }
            }
        });
        this.page = 0;
        this.model.getHistoryVideo(0);
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void onFirstUserVisible() {
        super.onFirstUserVisible();
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        if (!isOnClick()) {
            NovelHistory novelHistory = (NovelHistory) this.adapter.getDataInPosition(i);
            if (1 == novelHistory.getFictionType()) {
                ARouter.getInstance().build(Constance.NOVEL_ACTIVITY).withInt(Key.NOVEL_ID, novelHistory.getFictionId()).navigation();
            }
            if (2 == novelHistory.getFictionType()) {
                ARouter.getInstance().build(Constance.VOICE_NOVEL_ACTIVITY_NEW).withInt(Key.NOVEL_ID, novelHistory.getFictionId()).navigation();
            }
        }
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        int i = this.page + 1;
        this.page = i;
        this.model.getHistoryVideo(i);
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.page = 0;
        this.model.getHistoryVideo(0);
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        super.onDestroy();
    }
}
